package com.foreveross.mofang.serviceconsole.application.dto;

import java.util.Date;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.openkoala.koala.springmvc.JsonTimestampSerializer;
import org.springframework.format.annotation.DateTimeFormat;

import com.foreveross.mofang.serviceconsole.core.NodeRegister;

/**
 * 注册报道dto类
 * 
 * @author fb
 *
 */
public class NodeRegisterDTO extends BaseDTO<NodeRegister> {

	/**
	 *       
	 */
	private static final long serialVersionUID = 1L; 

	private Long id;

	@JsonSerialize(using=JsonTimestampSerializer.class)
	private Date lastHeartbeatConnectionDate;

	private String serverAdapterVersion;

	@NotNull(message = "结点序列号不能为空!")
	@Size(max = 36, message = "结点序列号不能超过36个字符")
	private String nodeSn;

	@NotNull(message = "结点适配器版本不能为空!")
	@Size(max = 150, message = "结点适配器版不能超过150个字符")
	private String clientAdapterVersion;

	@JsonSerialize(using=JsonTimestampSerializer.class)
	private Date registerDate;

	@NotNull(message = "结点名称不能为空!")
	@Size(max = 150, message = "结点不能超过150个字符")
	private String name;

	@NotNull(message = "任务监控url不能为空!")
	@Size(max = 150, message = "入口地址长度不能超过250个字符")
	@Pattern(regexp = "[http|https]+[://]+[0-9A-Za-z:/[-]_#[?][=][.][&]]*", message = "url格式错误")
	private String taskUrl;

	@NotNull(message = "结点ip不能为空!")
	@Size(max = 15, message = "结点不能超过15个字符")
	private String ip;
	
	@NotNull(message = "结点端口不能为空!")
	private Integer port;

	private Boolean isOnLine;
	
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	private Date startDate;
	
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	private Date endDate;

	public NodeRegisterDTO() {

	}

	public NodeRegisterDTO(Date lastHeartbeatConnectionDate, Date registerDate,
			String serverAdapterVersion, String nodeSn,
			String clientAdapterVersion, String name, String taskUrl,
			String ip, Integer port) {
		super();
		this.registerDate = registerDate;
		this.lastHeartbeatConnectionDate = lastHeartbeatConnectionDate;
		this.serverAdapterVersion = serverAdapterVersion;
		this.nodeSn = nodeSn;
		this.clientAdapterVersion = clientAdapterVersion;
		this.name = name;
		this.taskUrl = taskUrl;
		this.ip = ip;
		this.port = port;
	}

	public Boolean getIsOnLine() {
		return isOnLine;
	}

	public void setIsOnLine(Boolean isOnLine) {
		this.isOnLine = isOnLine;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Date getLastHeartbeatConnectionDate() {
		return lastHeartbeatConnectionDate;
	}

	public void setLastHeartbeatConnectionDate(Date lastHeartbeatConnectionDate) {
		this.lastHeartbeatConnectionDate = lastHeartbeatConnectionDate;
	}

	public String getServerAdapterVersion() {
		return serverAdapterVersion;
	}

	public void setServerAdapterVersion(String serverAdapterVersion) {
		this.serverAdapterVersion = serverAdapterVersion;
	}

	public String getNodeSn() {
		return nodeSn;
	}

	public void setNodeSn(String nodeSn) {
		this.nodeSn = nodeSn;
	}

	public String getClientAdapterVersion() {
		return clientAdapterVersion;
	}

	public void setClientAdapterVersion(String clientAdapterVersion) {
		this.clientAdapterVersion = clientAdapterVersion;
	}

	public Date getRegisterDate() {
		return registerDate;
	}

	public void setRegisterDate(Date registerDate) {
		this.registerDate = registerDate;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getTaskUrl() {
		return taskUrl;
	}

	public void setTaskUrl(String taskUrl) {
		this.taskUrl = taskUrl;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public Integer getPort() {
		return port;
	}

	public void setPort(Integer port) {
		this.port = port;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}
 
	@Override  
	public void domain2Dto(NodeRegister nodeRegister) {
		this.setClientAdapterVersion(nodeRegister.getClientAdapterVersion());
		this.setId(nodeRegister.getId());
		this.setIp(nodeRegister.getIp());
		this.setLastHeartbeatConnectionDate(nodeRegister.getLastHeartbeatConnectionDate());
		this.setName(nodeRegister.getNodeName());
		this.setNodeSn(nodeRegister.getNodeSn());
		this.setRegisterDate(nodeRegister.getRegisterDate());
		this.setServerAdapterVersion(nodeRegister.getServerAdapterVersion());
		this.setTaskUrl(nodeRegister.getTaskUrl());
		this.setPort(nodeRegister.getPort());
	}
 
	@Override
	public void dto2Domain(NodeRegister nodeRegister) {
		nodeRegister.setId(nodeRegister.getId());
		nodeRegister.setClientAdapterVersion(this.getClientAdapterVersion());
		nodeRegister.setIp(this.getIp());
		nodeRegister.setNodeName(this.getName());
		nodeRegister.setNodeSn(this.getNodeSn()); 
		nodeRegister.setServerAdapterVersion(this.getServerAdapterVersion());
		nodeRegister.setTaskUrl(this.getTaskUrl());
		nodeRegister.setPort(this.getPort());
	}    
}